(() => {
	// 页面刚开始调用请求获取数据
	let ele = {};
	ele.zufang_list = $("#zufang_list");
	ele.modal_tishi = $("#modal-tishi");
	ele.wenhao = $("#wenhao");
	ele.zanwu = $("#zanwu");
	ele.chahao = $("#chahao");
	ele.btn_que = $("#btn_que");
	ele.modal_prompt = $("#modal-prompt");
	ele.btn_que2 = $("#btn_que2");
	// ele.lianzu_top = $("#lianzu_top");
	// ele.zupinMoney = $("#zupinMoney");
	ele.chahao2 = $("#chahao2");
	// ele.shengyu = $("#shengyu");
	// ele.zupin = $("#zupin");
	ele.housre = $("#housre");
	let list = [{
		state: "1"
	}, {
		state: "2"
	}, {
		state: "1"
	}];
	let obj = {};

	// initList();

	// 点击问号弹出提示
	ele.wenhao.onclick = () => {
		openMdl(ele.modal_tishi);
	};
	// 点击查或者确认关闭提提示
	ele.chahao.onclick = () => {
		closeMdl(ele.modal_tishi);
	};
	ele.btn_que.onclick = () => {
		closeMdl(ele.modal_tishi);
	};
	ele.chahao2.onclick = () => {
		closeMdl(ele.modal_prompt);
	};

	// 如果有租住点击其他租住弹出框
	ele.wenhao.onclick = () => {
		openMdl(ele.modal_tishi);
	};
	initAsync();

	function initAsync() {
		let token = getCookie("token");
		ajax({
			method: "get",
			url: API_PATH.HOMEDETAIL,
			header: {
				Authorization: token,
			},
			data: {
				id: 1,
			},
			success: (res) => {
				obj = res.data.realEstate; //租房信息
				initList();
			},
			error: (err) => {
				// openTips(err.msg);
			},
		});
	}

	function initList() {
		if (list.length == 0) {
			closeMdl(ele.zufang_list);
			openMdl(ele.zanwu);
		}
		let newList = list
			.map((item, index) => {
				return `
      <div class="son_list">
        <div class="left">
          <div class="num">${index + 1}</div>
          <div class="touxiang">
            <img src="http://img.qxgs.cc/tiantianlaishouzu/img/low_Ent_ousing/touxiang2.png" alt="" />
          </div>
          <div class="cen_title">
            <div class="name"><span>房东：</span><span>杜拉拉</span></div>
            <div class="residue">
              <span>剩余房间：</span><span class="residue_num">1/4</span>
            </div>
            <div class="zhi">
              <span>本楼豪华值：</span><span class="zhi_num">19999</span>
            </div>
        
          </div>
        </div>
        <div class="right">
          <!-- 可有可无的租住 -->
          <div class="btn_zuzhu">
            <div id="monery_btn" data-id="${item.state}" class="${
          item.state == 1 ? "monery_btn" : "monery_btn2"
        }">${item.state == 1 ? "租住" : "进入"}</div>
          </div>
          <!-- 可有可无的到期 -->
         <!-- <div class="tabs_biao"><p>快到期</p></div>-->
        </div>
      </div>
      `;
			})
			.join(" ");
		ele.zufang_list.innerHTML = newList;
		//点租住
		let btnAll = document.querySelectorAll("#monery_btn");
		btnAll.forEach((item) => {
			item.onclick = (e) => {
				console.log(e.target.dataset.id);
				if (e.target.dataset.id == 1) {
					// 说明是租住

					openMdl(ele.modal_prompt);
				}
			};
		});
		// // 处理是否显示上面的租房
		// if (obj.is_owner == 0) {
		//   console.log(555);
		//   closeMdl(ele.shengyu);
		//   ele.lianzu_top.style.display = "block";
		//   ele.zupin.innerHTML = "租赁";
		//   ele.zupinMoney.innerHTML = obj.hire_money;
		// } else {
		//   //说明是购买
		//   openMdl(ele.shengyu);
		//   ele.zupin.innerHTML = "购买";
		//   ele.zupinMoney.innerHTML = obj.money;
		//   ele.lianzu_top.style.display = "none";
		// }
		// 小时渲染
		ele.housre.innerHTML = obj.power;
	}
})();